package com.hqd.ch03.v49.aop.config;

import com.hqd.ch03.v49.aop.framework.AopInfrastructureBean;
import com.hqd.ch03.v49.aop.framework.aspectj.AspectInstanceFactory;
import com.hqd.ch03.v49.aware.BeanFactoryAware;
import com.hqd.ch03.v49.core.Ordered;
import com.hqd.ch03.v49.factory.BeanFactory;
import lombok.Data;

@Data
public class SimpleBeanFactoryAwareAspectInstanceFactory implements AspectInstanceFactory, BeanFactoryAware, AopInfrastructureBean {
    private String aspectBeanName;

    private BeanFactory beanFactory;

    public void setAspectBeanName(String aspectBeanName) {
        this.aspectBeanName = aspectBeanName;
    }

    @Override
    public Object getAspectInstance() {
        return this.beanFactory.getBean(this.aspectBeanName);
    }

    @Override
    public ClassLoader getAspectClassLoader() {
        return Thread.currentThread().getContextClassLoader();
    }

    @Override
    public int getOrder() {
        return Ordered.LOWEST_PRECEDENCE;
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) {
        this.beanFactory = beanFactory;
    }
}
